package com.youcash.ZyWallet_spring.controller;

import com.youcash.ZyWallet_spring.entity.CustomersLoans;
import com.youcash.ZyWallet_spring.service.CustomersLoansService;
import com.youcash.ZyWallet_spring.vo.ResultVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Zhangzifeng
 */
@RestController
@RequestMapping("/apply")
//类注解：可以对控制器类进行详细说明
@Api(value = "提供贷款申请或审批的相关接口", tags = "客户贷款管理")
@CrossOrigin
public class CustomersLoansController {

    @Autowired
    private CustomersLoansService customersLoansService;

    @PostMapping("/add")
    @ApiOperation("提交申请的接口")
    public ResultVO addApplication(@RequestBody CustomersLoans customersLoans) {
        return customersLoansService.submitApplication(customersLoans);
    }

    @GetMapping("/get")
    @ApiOperation("获取申请列表的接口")
    public ResultVO listApplication() {
        return customersLoansService.listApplication();
    }

    @GetMapping("/getById/{customersId}")
    @ApiOperation("通过Id获取申请记录的接口")
    @ApiImplicitParam(dataType = "Integer", name = "customersId", value = "用户id", required = true)
    public ResultVO listApplicationById(@PathVariable("customersId") Integer customersId) {
        return customersLoansService.listApplicationById(customersId);
    }

    @GetMapping("/getStatus/{id}")
    @ApiOperation("通过Id获取申请记录的状态")
    @ApiImplicitParam(dataType = "Integer", name = "id", value = "申请记录的id", required = true)
    public ResultVO getStatusById(@PathVariable("id") Integer id) {
        return customersLoansService.getStatusById(id);
    }

    @PutMapping("/updateStatus/{id}/{status}")
    @ApiOperation("更新Id获取申请记录的状态")
    @ApiImplicitParams({
            //方法注解：说明接口方法的参数
            @ApiImplicitParam(
                    dataType = "Integer", name = "id", value = "申请记录的id", required = true),
            @ApiImplicitParam(
                    dataType = "Integer", name = "status", value = "状态", required = true)
    })
    public ResultVO updateStatusById(@PathVariable("id") Integer id,
                                     @PathVariable("status") Integer status) {
        return customersLoansService.updateStatus(id, status);
    }

    @GetMapping("/listStatus/{customersId}/{status}")
    @ApiOperation("获取为“已通过”状态的申请")
    @ApiImplicitParams({
            //方法注解：说明接口方法的参数
            @ApiImplicitParam(
                    dataType = "Integer", name = "customersId", value = "用户id", required = true),
            @ApiImplicitParam(
                    dataType = "Integer", name = "status", value = "状态", required = true)
    })
    public ResultVO listStatusByCustomersId(@PathVariable("customersId") Integer customersId,
                                            @PathVariable("status") Integer status) {
        return customersLoansService.listStatusByCustomersId(customersId, status);
    }
}
